package com.seeyon.bugfixtools.custom.config;

import com.seeyon.bugfixtools.custom.datasource.interceptor.DatasourceInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author cans
 * @date 2024/5/5
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private DatasourceInterceptor datasourceInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(datasourceInterceptor).addPathPatterns("/**")
                .excludePathPatterns("index.html")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/datasource/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
